#script2301.py - HD Presentation
#Written by Blum and Bresnahan
# 
##########################################
#
##### Import Modules & Variables ######
import os			#Import OS module
import pygame			#Import PyGame library
import sys			#Import System module
#
from pygame.locals import *	#Load PyGame constants
#
pygame.init()			#Initialize PyGame
#
# Set up Picture Variables #####################
# 
PictureDirectory='/home/pi/pictures'
PictureFileExtension='.jpg'
PictureDisk='/dev/sda1'
#
# Mount the Picture Drive ######################
#
Command="sudo umount " + PictureDisk + " 2>/dev/null"
os.system(Command)
Command="sudo mount -t vfat " + PictureDisk + " " + PictureDirectory
os.system(Command)
#
# Set up Presentation Screen ###################
#
ScreenColor=Gray= 125,125,125
#
ScreenFlag=FULLSCREEN | NOFRAME
PrezScreen=pygame.display.set_mode((0,0),ScreenFlag)
#
PrezScreenRect=PrezScreen.get_rect()
CenterScreen=PrezScreenRect.center
#
PrezScreenSize=PrezScreen.get_size()
Scale=PrezScreenSize[0]-20,PrezScreenSize[1]-20
#
###### Run the Presentation  #######################################
#
while True:
	#
	#Get HD Pictures ###################################
	#
	for Picture in os.listdir(PictureDirectory):
		if Picture.endswith(PictureFileExtension):
			Picture=PictureDirectory + '/' + Picture
			Picture=pygame.image.load(Picture).convert_alpha()
			#
			# If Picture is bigger than screen, scale it down.
			if Picture.get_size() > PrezScreenSize:
				Picture=pygame.transform.scale(Picture,Scale)
			#
			PictureLocation=Picture.get_rect()  #Current location 
			PictureLocation.center=CenterScreen #Put picture in center of screen
			#
			#Display HD Images to Screen #################3
			PrezScreen.fill(ScreenColor)
			PrezScreen.blit(Picture,PictureLocation)
			pygame.display.update()
			pygame.time.delay(500)
			#
			# Quit with Mouse or Keyboard if Desired
			for Event in pygame.event.get():
				if Event.type in (QUIT,KEYDOWN,MOUSEBUTTONDOWN):
					Command = "sudo umount " + PictureDisk
					os.system(Command)
					sys.exit()
#
